#pragma once

#include "pch.h"
#include "VertexPositionCoord.h"

ref class SinglePreviewRenderer sealed
{
internal:
	SinglePreviewRenderer();

	void CreateDeviceResources(ID3D11Device1 *pDevice);
	void CreatePreviewTexture();

	void ReleaseDeviceResources();
	void ReleasePreviewTexture();

	BOOL CheckForDeviceChange(ID3D11Device1* pDevice);

	void UpdateForPropertyChange(
		Windows::Foundation::Size resolution,
		Windows::Foundation::Rect rect,
		Nokia::Graphics::Imaging::Rotation rotation,
		Nokia::Graphics::Imaging::FlipMode flip,
		ID3D11DeviceContext1* pContext
		);

	void Update(
		Nokia::Graphics::Imaging::IImageProvider^ source,
		ID3D11DeviceContext1* pContext
		);
	void Render(ID3D11Device1 *pDevice, ID3D11DeviceContext1 *pContext);

private:
	BOOL m_initialized;

	DirectX::XMFLOAT2 m_resolution;

	ID3D11Device1 *m_pDevice;
	ID3D11DeviceContext1 *m_pContext;

	ID3D11InputLayout *m_pInputLayout;
	ID3D11Buffer *m_pVertexBuffer;
	VERTEX_POSITION_COORD m_pVertexData[4];

	ID3D11VertexShader *m_pVertexShader;
	ID3D11PixelShader *m_pPixelShader;

	DirectX::XMUINT2 m_previewTextureSize;
	ID3D11SamplerState *m_pPreviewTextureSampler;
	ID3D11Texture2D *m_pPreviewTexture;
	ID3D11ShaderResourceView *m_pPreviewTextureView;
};